<template>
  <view class="content">
    <view class="info-img-box">
      <u-avatar :src="info.avatar_url" :size="160" />
      <view class="info-right">
        <view class="name">{{ info.githubUsername }}</view>
        <view class="fs-12">积分：{{ info.score }}</view>
        <view class="fs-12">创建时间：{{ dateFormat(info.create_at) }}</view>
      </view>
    </view>
    <view class="Collapse-box">
      <CollapseItem :list="collection" title="我的收藏" />
      <CollapseItem :list="info.recent_replies" title="最近回复" />
      <CollapseItem :list="info.recent_topics" title="最近帖子" />
    </view>
  </view>
</template>

<script>
import { dateFormat } from "@/utils/format.js";
import { getUserInfoUrl, getCollectionUrl } from "@/api/user.js";
import CollapseItem from "./collapse-item.vue";
export default {
  components: {
    CollapseItem,
  },
  props: {
    name: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      info: {},
      dateFormat,
      collection: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.getUserInfoFn(this.name);
      this.getCollectionFn(this.name);
    },
    getUserInfoFn(name) {
      getUserInfoUrl(name).then((res) => {
        this.info = res.data;
      });
    },
    getCollectionFn(name) {
      getCollectionUrl(name).then((res) => {
        this.collection = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.info-img-box {
  display: flex;
  align-items: center;
  padding: 20rpx;
  .info-right {
    margin-left: 20rpx;
    view {
      padding-top: 10rpx;
    }
    .name {
      font-size: 32rpx;
      font-weight: 700;
    }
  }
}
.Collapse-box {
  padding: 20rpx;
}
</style>
